package com.OrderingSystem.controller.seller;

import com.OrderingSystem.service.ILoginlogService;
import com.OrderingSystem.service.IOrderMasterService;
import com.OrderingSystem.service.IProductInfoService;
import com.OrderingSystem.service.UserService;
import com.OrderingSystem.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Api(tags = "数据统计接口")
@RestController
@RequestMapping("/statistics")
@ApiResponses({
        @ApiResponse(code = 200, message = "请求成功", response = Result.class),
        @ApiResponse(code = 403, message = "没有权限"),
        @ApiResponse(code = 404, message = "资源不存在"),
        @ApiResponse(code = 500, message = "服务器错误")
})
public class StatisticsController {

    @Autowired
    private IOrderMasterService orderMasterService;

    @Autowired
    private ILoginlogService loginlogService;

    @Autowired
    private IProductInfoService productInfoService;

    @ApiOperation("获取统计概览数据")
    @GetMapping("/overview")
    public Result getStatisticsOverview() {
        Map<String, Object> statistics = new HashMap<>();

        // 获取今日订单数
        Integer todayOrders = orderMasterService.getTodayOrderCount();
        statistics.put("todayOrders", todayOrders);

        // 获取活跃用户数（最近5天内登录）
        Integer activeUsers = loginlogService.getActiveUserCount(5);
        statistics.put("activeUsers", activeUsers);

        // 获取餐品总数
        Integer totalProducts = productInfoService.getTotalProductCount();
        statistics.put("totalProducts", totalProducts);

        // 获取订单总金额
        BigDecimal totalAmount = orderMasterService.getTotalOrderAmount();
        statistics.put("totalAmount", totalAmount);

        return Result.success(statistics);
    }
}
